<?php
namespace app\superadmin\controller;
use think\Controller;
use app\superadmin\model\Login as Log;
use think\Captcha;

class Login extends Controller
{
    public function index()
    {
        $captcha=input('request.captcha');
    	if(request()->isPost()){//如果是post方式提交过来，就执行登录操作
            if(!captcha_check($captcha)){
                //$this->error('验证码输入错误！');
                //echo "&nbsp;&nbsp;&nbsp;验证码输入错误！";
                echo("<script type='text/javascript'> alert('验证码错误！');</script>");
            }else{
    		$login=new Log;//实例化model类
    		$status=$login->login(input('adminname'),input('adminpass'));//login指向login方法，login方法传递两个值  
    		if($status==1){
                //return $this->success('Index/index');
    			return $this->redirect('Index/index');
    		}
    		elseif($status==2){
    			//return $this->error('账号或者密码错误！');
                //echo "&nbsp;&nbsp;&nbsp;账号或者密码错误！";
                echo("<script type='text/javascript'> alert('账号或者密码错误！');</script>");
    		}
    		else{
    			//return $this->error('用户不存在！');
                //echo "&nbsp;&nbsp;&nbsp;用户不存在！";
                echo("<script type='text/javascript'> alert('用户不存在！');</script>");
    		}
    	}
        }

        return $this->fetch();
         //echo $data['captcha'];die;
    }


    public function logout(){
    	session(null);//清空session
    	return $this->success('注销成功！','index');
    }

}
